﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BahdlClassLib;
using BusinessLayer;
using BusinessLayer.DTO;

namespace PayRoll
{
    public partial class EmployeeJoining : CustomFormTemplate
    {
        int intEmployeeID = 0;
        bool blMyProfile = false;

        public EmployeeJoining()
        {
            InitializeComponent();
        }

        //To open for Employee view
        public EmployeeJoining(int intID, bool blProfile)
        {
            InitializeComponent();
            intEmployeeID = intID;
            blMyProfile = blProfile;
            this.Text = "My Profile";

            set_ToolBarButtonVisible("add", false);
            set_ToolBarButtonVisible("edit", false);
            set_ToolBarButtonVisible("delete", false);
            set_ToolBarButtonVisible("print", false);
            set_ToolBarButtonVisible("find", false);

        }

        void EmployeeJoining_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == System.Windows.Forms.Keys.Escape)
            {
                if (this.Tag.ToString() == "view")
                {
                    EmployeeJoining_ToolBarButtonClick("exit");
                }
                else
                {
                    EmployeeJoining_ToolBarButtonClick("revert");
                }
            }
        }
        void EmployeeJoining_EnableControls(bool Enable)
        {
            fraDtl.Enabled = Enable;
        }
        private void EmployeeJoining_ToolBarButtonClick(string Button)
        {
            if (CommonFunction.InList(Button, "add", "edit", "delete") == true)
            {
                if ((Button == "edit" || Button == "delete"))
                {
                    if (txtUserName.Text == "")
                    {
                        return;
                    }
                }
            }
            switch (Button)
            {
                case "exit":
                    if (UIFunction.SureToExit("") == true)
                    {
                        ClearError();
                        this.Close();
                    }
                    break;
                case "revert":
                    ClearError();
                    this.Tag = "view";
                    EmployeeJoining_EnableControls(false);
                    this.ToolBarEnterEditMode = false;
                    break;
                case "print":
                    //CrytalEditor newObject = new CrytalEditor();
                    //DataSet dsLocal = new DataSet();
                    //string CompanyDescr = getCompanyData();
                    //CompanyDescr = CompanyDescr + "Raw Material Checklist";
                    //try {
                    //    OpenBlClass();
                    //    dsLocal.Tables.Add(blRM.GetDataTable("Select * From Mst_Authority where Cocd = " + objCompany.Code + " Order by Descr", "mst_Approval"));
                    //    newObject.LoadPreviewer("Rep_Mst_Approval.rpt", dsLocal, enmReportType.FAMasters, CompanyDescr);
                    //} catch {
                    //} finally {
                    //    CloseBlClass();
                    //    newObject = null;
                    //    dsLocal = null;
                    //}
                    break;
                case "find":
                    ClearError();
                    DialogResult result = MessageBox.Show("Select Yes to see all employees(Resigned/Active) and No to see all Active Employees.", "Info", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    DataSet dsLocal = new DataSet();
                    Popup popup = new Popup();
                    try
                    {
                        ClsEmployee objClsEmployee = new ClsEmployee();
                        if (result == DialogResult.Yes)
                        {
                            dsLocal.Tables.Add(objClsEmployee.GetAllEmployees());
                        }
                        else
                        {
                            dsLocal.Tables.Add(objClsEmployee.GetAllActiveEmployees());
                        }
                        dsLocal.Tables[0].TableName = "popup";
                        popup.Width = 50;
                        popup.ShowPopup(null, "EmployeeID", ref dsLocal, "popup", "EmployeeID,LoginID,FirstName,MiddleName,LastName", "", "Manage Employees", "ID,User ID,First Name,Middle Name,Last Name", "5,8,11,11,11");
                        if (!string.IsNullOrEmpty(CommonFunction.NullToString(popup.ReturnValue())))
                        {
                            uiGetData(Convert.ToInt32(popup.Field("EmployeeID")));
                            tabControl.SelectTab(0);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    finally
                    {
                        dsLocal = null;
                        popup = null;
                    }
                    break;
                case "add":
                    ClearError();
                    if (uiGetData(0))
                    {
                        this.ToolBarEnterEditMode = true;
                        this.Tag = "add";
                        EmployeeJoining_EnableControls(true);
                        txtName.Select();
                    }
                    break;
                case "edit":
                    ClearError();
                    this.ToolBarEnterEditMode = true;
                    this.Tag = "edit";
                    EmployeeJoining_EnableControls(true);
                    txtName.Select();
                    dtJoiningDate.Enabled = false;
                    //chkSalaried.Enabled = false;
                    break;
                case "save":
                       if (!ValidateName())
                        return;
                    if (uiPutData() == true & this.Tag.ToString() == "edit")
                    {
                        
                        this.Tag = "view";
                        this.ToolBarEnterEditMode = false;
                        EmployeeJoining_EnableControls(false);
                    }
                    break;
                case "delete":
                    ClearError();
                    uiDeleteData();
                    break;
            }


        }
        private void uiDeleteData()
        {
            try
            {
                ClsEmployee clsDesignation = new ClsEmployee();
                clsDesignation.EmployeeID = Convert.ToInt32(fraDtl.Tag);
                clsDesignation.DeleteEmployee();
                uiGetData(0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private bool uiPutData()
        {
            bool functionReturnValue = false;
            try
            {
                ClsEmployee objClsEmployee = new ClsEmployee();
                objClsEmployee.EmployeeID = Convert.ToInt32(fraDtl.Tag);
                objClsEmployee.FirstName = txtName.Text;
                objClsEmployee.LastName = txtLname.Text;
                objClsEmployee.MiddleName = txtMname.Text;
                objClsEmployee.DOB = Convert.ToDateTime(dtDOB.Text);
                objClsEmployee.Qualification = txtQualification.Text;
                objClsEmployee.Phone = txtPhone.Text;
                objClsEmployee.PhoneHome = txtHomePhone.Text;
                objClsEmployee.EmailID = txtEmailID.Text;
                objClsEmployee.IdentityProof = txtIdentityProof.Text;
                objClsEmployee.Address = txtAddress.Text;
                objClsEmployee.City = txtCity.Text;
                objClsEmployee.State = txtState.Text;
                objClsEmployee.Country = txtCountry.Text;
                objClsEmployee.Pin = txtPIN.Text;
                objClsEmployee.EmploymentID = Convert.ToInt32(txtEmpType.Tag);
                objClsEmployee.DesignationID = Convert.ToInt32(txtDesignation.Tag);
                objClsEmployee.RoleID = Convert.ToInt32(txtRole.Tag);
                objClsEmployee.EmploymentStatusID = Convert.ToInt32(txtEmpStatus.Tag);
                objClsEmployee.DepartmentID = Convert.ToInt32(txtDepartment.Tag);
                objClsEmployee.JoiningDate = Convert.ToDateTime(dtJoiningDate.Text);
                objClsEmployee.Gender = (Utility.Gender)Enum.Parse(typeof(Utility.Gender), ddlGender.Text);
                objClsEmployee.MaritalStatus = (Utility.MaritalStatus)Enum.Parse(typeof(Utility.MaritalStatus), ddlMStatus.Text);
                objClsEmployee.Salaried = chkSalaried.Checked;
                objClsEmployee.HourlyRate = Convert.ToDecimal(txtHourlyRate.Text);
                objClsEmployee.OverTimeRate = Convert.ToDecimal(txtOverTimeRate.Text);
                objClsEmployee.IsAccountLocked = chkLocked.Checked;
                objClsEmployee.LeaveCarryForward = chkLeaveForward.Checked;
                objClsEmployee.NoOfLeave = Convert.ToInt32(txtNoOfAnnualNeave.Text);


                List<SalaryStructureInfo> SalaryStructures = new List<SalaryStructureInfo>();

                foreach (DataGridViewRow item in grdSalaryComponent.Rows)
                {
                    SalaryStructureInfo drSalaryStructureRow = new SalaryStructureInfo();
                    drSalaryStructureRow.SalaryHeadID = Convert.ToInt32(item.Cells["SalaryHeadID"].Value);
                    drSalaryStructureRow.SalaryHead = item.Cells["SalaryHead"].Value.ToString();
                    drSalaryStructureRow.Amount = Convert.ToDecimal(item.Cells["Amount"].Value);
                    drSalaryStructureRow.DeductSalaryIfAbsent = Convert.ToBoolean(item.Cells["DeductSalaryIfAbsent"].Value);
                    SalaryStructures.Add(drSalaryStructureRow);
                }
                objClsEmployee.SalaryStructures = SalaryStructures;

                if (objClsEmployee.SaveEmployee(this.Tag.ToString()))
                    functionReturnValue = true;
                uiGetData(0);

                if (this.Tag.ToString() == "add")
                    txtName.Select();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {

            }
            return functionReturnValue;
        }
        private bool uiGetData(int KeyField)
        {
            bool functionReturnValue = false;
            try
            {
                ClsEmployee clsEmployee = new ClsEmployee();
                //Make object of Leave Class
                ClsLeave objClsLeave = new ClsLeave();
                objClsLeave.GetNoOfLeave(KeyField);

                clsEmployee.GetEmployee(KeyField);
                fraDtl.Tag = clsEmployee.EmployeeID;
                txtName.Text = clsEmployee.FirstName;
                txtLname.Text = clsEmployee.LastName;
                txtMname.Text = clsEmployee.MiddleName;
                dtDOB.Text = clsEmployee.DOB.ToString();
                txtQualification.Text = clsEmployee.Qualification;
                txtPhone.Text = clsEmployee.Phone;
                txtHomePhone.Text = clsEmployee.PhoneHome;
                txtEmailID.Text = clsEmployee.EmailID;
                txtIdentityProof.Text = clsEmployee.IdentityProof;
                txtAddress.Text = clsEmployee.Address;
                txtCity.Text = clsEmployee.City;
                txtState.Text = clsEmployee.State;
                txtCountry.Text = clsEmployee.Country;
                txtPIN.Text = clsEmployee.Pin;
                txtEmpType.Tag = clsEmployee.EmploymentID;
                txtEmpType.Text = clsEmployee.EmploymentName;
                txtDesignation.Tag = clsEmployee.DesignationID;
                txtDesignation.Text = clsEmployee.Designation;
                txtRole.Tag = clsEmployee.RoleID;
                txtRole.Text = clsEmployee.Role;
                txtEmpStatus.Tag = clsEmployee.EmploymentStatusID;
                txtEmpStatus.Text = clsEmployee.EmploymentStatus;
                txtDepartment.Tag = clsEmployee.DepartmentID;
                txtDepartment.Text = clsEmployee.Department;
                txtUserName.Text = clsEmployee.LoginID;
                //dtLastLogin.Text = clsEmployee.LastLoginDate.ToString();
                lblLastLoginDate.Text = clsEmployee.LastLoginDate.ToString();
                dtJoiningDate.Text = clsEmployee.JoiningDate.ToString();
                chkSalaried.Checked = clsEmployee.Salaried;
                txtHourlyRate.Text = clsEmployee.HourlyRate.ToString();
                txtOverTimeRate.Text = clsEmployee.OverTimeRate.ToString();
                chkLocked.Checked = clsEmployee.IsAccountLocked;
                chkLeaveForward.Checked = clsEmployee.LeaveCarryForward;
                //Get data from AnnulaLeave Table
                txtNoOfAnnualNeave.Text = objClsLeave.NoOfLeave.ToString();

                grdSalaryComponent.DataSource = clsEmployee.SalaryStructures;
                grdSalaryComponent.Columns[0].Visible = false;
                grdSalaryComponent.Columns[1].ReadOnly = true;
                grdSalaryComponent.Columns[3].ReadOnly = true;
                grdSalaryComponent.Columns[4].ReadOnly = true;
                functionReturnValue = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {

            }
            return functionReturnValue;
        }

        private void EmployeeJoining_Load(object sender, EventArgs e)
        {
            this.Left = 0;
            this.Top = 0;
            this.Tag = "view";
            txtName.Text = "";
            txtLname.Text = "";
            txtMname.Text = "";
            dtDOB.Text = DateTime.Now.ToString();
            txtQualification.Text = "";
            txtPhone.Text = "";
            txtHomePhone.Text = "";
            txtEmailID.Text = "";
            txtIdentityProof.Text = "";
            txtAddress.Text = "";
            txtCity.Text = "";
            txtState.Text = "";
            txtCountry.Text = "";
            txtPIN.Text = "";
            txtEmpType.Text = "";
            txtEmpType.Tag = 0;
            txtDesignation.Text = "";
            txtDesignation.Tag = 0;
            txtRole.Text = "";
            txtRole.Tag = 0;
            txtEmpStatus.Text = "";
            txtEmpStatus.Tag = 0;
            txtDepartment.Text = "";
            txtDepartment.Tag = 0;
            txtUserName.Text = "";
            //dtLastLogin.Text = DateTime.Now.ToString();
            lblLastLoginDate.Text = DateTime.Now.ToString();
            dtJoiningDate.Text = DateTime.Now.ToString();
            dtdResignDate.Text = Utility.GetDateYYYYMMDD(new DateTime(1900, 01, 01));
            ddlGender.Items.Clear();
            ddlGender.Items.Add(Utility.Gender.Female.ToString());
            ddlGender.Items.Add(Utility.Gender.Male.ToString());
            ddlGender.SelectedIndex = 1;
            ddlMStatus.Items.Add(Utility.MaritalStatus.Single.ToString());
            ddlMStatus.Items.Add(Utility.MaritalStatus.Married.ToString());
            ddlMStatus.Items.Add(Utility.MaritalStatus.Widow.ToString());
            ddlMStatus.SelectedIndex = 1;
            chkSalaried.Checked = true;
            txtHourlyRate.Text = "";
            txtOverTimeRate.Text = "";
            chkLocked.Checked = false;
            chkLeaveForward.Checked = false;
            txtNoOfAnnualNeave.Text = string.Empty;
            grdSalaryComponent.DataSource = null;

            base.ToolBarButtonClick += new ToolBarButtonClickEventHandler(EmployeeJoining_ToolBarButtonClick);
            base.EnableControls += new EnableControlsEventHandler(EmployeeJoining_EnableControls);
            base.KeyDown += new KeyEventHandler(EmployeeJoining_KeyDown);


            //Show user Data in case called from My Profile
            if (blMyProfile)
            {
                uiGetData(Convert.ToInt32(intEmployeeID));
                tabControl.SelectTab(0);
                groupBox3.Enabled = false;
                groupBox4.Enabled = false;
                groupBox5.Enabled = false;
                groupBox1.Enabled = false;
                groupBox2.Enabled = false;
                grpSalaryComponent.Enabled = false;
                fraDtl.Enabled = true;

            }
        }

        private void txtEmpType_ButtonClick()
        {
            DataSet dsLocal = new DataSet();
            Popup popup = new Popup();
            ClsEmploymentType clsEmploymentType = new ClsEmploymentType();
            dsLocal.Tables.Add(clsEmploymentType.GetAllEmployments());
            dsLocal.Tables[0].TableName = "popup";
            popup.Width = 50;
            popup.ShowPopup(null, "EmploymentTypeID", ref dsLocal, "popup", "EmploymentType", "", "EmploymentType Master", "Employment Type", "10,20");
            if (!string.IsNullOrEmpty(CommonFunction.NullToString(popup.ReturnValue())))
            {
                clsEmploymentType.GetEmployment(Convert.ToInt32(popup.Field("EmploymentTypeID")));
                txtEmpType.Tag = popup.ReturnValue();
                txtEmpType.Text = clsEmploymentType.EmploymentType;
            }

        }

        private void txtDesignation_ButtonClick()
        {
            DataSet dsLocal = new DataSet();
            Popup popup = new Popup();
            ClsDesignation clsDesignation = new ClsDesignation();
            dsLocal.Tables.Add(clsDesignation.GetAllDesignations());
            dsLocal.Tables[0].TableName = "popup";
            popup.Width = 50;
            popup.ShowPopup(null, "DesignationID", ref dsLocal, "popup", "Designation", "", "Designation Master", "Designation", "10,20");
            if (!string.IsNullOrEmpty(CommonFunction.NullToString(popup.ReturnValue())))
            {
                clsDesignation.GetDesignation(Convert.ToInt32(popup.Field("DesignationID")));
                txtDesignation.Tag = popup.ReturnValue();
                txtDesignation.Text = clsDesignation.Designation;
            }
            //else
            //{
            //    txtDesignation.Tag = 0;
            //    txtDesignation.Text = "";
            //}
        }

        private void txtRole_ButtonClick()
        {
            DataSet dsLocal = new DataSet();
            Popup popup = new Popup();
            ClsRoleMaster clsRoleMaster = new ClsRoleMaster();
            dsLocal.Tables.Add(clsRoleMaster.GetAllRole());
            dsLocal.Tables[0].TableName = "popup";
            popup.Width = 50;
            popup.ShowPopup(null, "RoleID", ref dsLocal, "popup", "Role", "", "Role Master", "Role", "10,20");
            if (!string.IsNullOrEmpty(CommonFunction.NullToString(popup.ReturnValue())))
            {
                clsRoleMaster.GetRole(Convert.ToInt32(popup.Field("RoleID")));
                txtRole.Tag = popup.ReturnValue();
                txtRole.Text = clsRoleMaster.Role;
            }
            //else
            //{
            //    txtRole.Tag = 0;
            //    txtRole.Text = "";
            //}
        }

        private void txtEmpStatus_ButtonClick()
        {
            DataSet dsLocal = new DataSet();
            Popup popup = new Popup();
            ClsEmploymentStatusType clsEmploymentStatusType = new ClsEmploymentStatusType();
            dsLocal.Tables.Add(clsEmploymentStatusType.GetAllEmploymentsStatusTypes());
            dsLocal.Tables[0].TableName = "popup";
            popup.Width = 50;
            popup.ShowPopup(null, "EmploymentStatusID", ref dsLocal, "popup", "EmploymentStatus", "", "EmploymentStatus Master", "EmploymentStatus", "10,20");
            if (!string.IsNullOrEmpty(CommonFunction.NullToString(popup.ReturnValue())))
            {
                clsEmploymentStatusType.GetEmploymentStatusTypes(Convert.ToInt32(popup.Field("EmploymentStatusID")));
                txtEmpStatus.Tag = popup.ReturnValue();
                txtEmpStatus.Text = clsEmploymentStatusType.EmploymentStatus;
            }
            //else
            //{
            //    txtEmpStatus.Tag = 0;
            //    txtEmpStatus.Text = "";
            //}
        }

        private void chkSalaried_CheckedChanged(object sender, EventArgs e)
        {
            if (chkSalaried.Checked)
            {
                txtHourlyRate.Text = "";
                txtHourlyRate.Enabled = false;
                grpSalaryComponent.Enabled = true;
                txtNoOfAnnualNeave.Enabled = true;
                chkLeaveForward.Enabled = true;

            }
            else
            {
                txtHourlyRate.Enabled = true;
                grpSalaryComponent.Enabled = false;
                txtNoOfAnnualNeave.Text = string.Empty;
                txtNoOfAnnualNeave.Enabled = false;
                chkLeaveForward.Checked = false;
                chkLeaveForward.Enabled = false;

            }
        }

        private void txtDepartment_ButtonClick()
        {
            DataSet dsLocal = new DataSet();
            Popup popup = new Popup();
            ClsDepartment objClsDepartment = new ClsDepartment();
            dsLocal.Tables.Add(objClsDepartment.GetAllDepartment());
            dsLocal.Tables[0].TableName = "popup";
            popup.Width = 50;
            popup.ShowPopup(null, "DepartmentID", ref dsLocal, "popup", "Department", "", "Department Master", "Department", "10,20");
            if (!string.IsNullOrEmpty(CommonFunction.NullToString(popup.ReturnValue())))
            {
                objClsDepartment.GetDepartment(Convert.ToInt32(popup.Field("DepartmentID")));
                txtDepartment.Tag = popup.ReturnValue();
                txtDepartment.Text = objClsDepartment.Department;
            }
            //else
            //{
            //    txtDepartment.Tag = 0;
            //    txtDepartment.Text = "";
            //}
        }

        private bool ValidateName()
        {
            bool bStatus = true;
            if (txtName.Text == "")
            {
                errorProvider1.SetError(txtName, "Please enter the First Name");
                return false;
            }
            if (txtName.Text.Length < 3)
            {                
                errorProvider1.SetError(txtName, "Please enter minimum 3 character");
                return false;
            }
            if (txtLname.Text == "")
            {
                errorProvider1.SetError(txtLname, "Please enter the Last Name");
                return false;
            }
            if (txtLname.Text.Length < 2)
            {
                errorProvider1.SetError(txtLname, "Please enter minimum 2 character");
                return false;
            }
            if (txtEmpType.Tag.ToString() == "0")
            {
                errorProvider1.SetError(txtEmpType, "Please select Employment Type");
                return false;
            }
            if (txtDesignation.Tag.ToString() == "0")
            {
                errorProvider1.SetError(txtDesignation, "Please select Designation");
                return false;
            }
            if (txtRole.Tag.ToString() == "0")
            {
                errorProvider1.SetError(txtRole, "Please select Role");
                return false;
            }
            if (txtEmpStatus.Tag.ToString() == "0")
            {
                errorProvider1.SetError(txtEmpStatus, "Please select Employment Status");
                return false;
            }
            if (txtDepartment.Tag.ToString() == "0")
            {
                errorProvider1.SetError(txtDepartment, "Please select Department");
                return false;
            }
            if (txtPhone.Text == "")
            {
                errorProvider1.SetError(txtPhone, "Please enter the Phone Number");
                return false;
            }

            ClearError();
            return bStatus;
        }
        private void ClearError()
        {
            errorProvider1.Clear();
        }

        private void txtMname_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtLname_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtName_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void ddlGender_Click(object sender, EventArgs e)
        {
            ClearError();
        }

        private void ddlMStatus_Click(object sender, EventArgs e)
        {
            ClearError();
        }

        private void dtDOB_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtQualification_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void dtJoiningDate_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void dtdResignDate_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtEmpType_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtDesignation_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtRole_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtEmpStatus_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtDepartment_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtPhone_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtHomePhone_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtEmailID_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtIdentityProof_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtAddress_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtCity_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtState_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtCountry_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtPIN_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtUserName_Validating(object sender, CancelEventArgs e)
        {
            ClearError();
        }

        private void txtPhone_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) || (int)e.KeyChar == 8)
            {
                e.Handled = false;
                ClearError();
            }

            else
            {
                errorProvider1.SetError(txtPhone, "Please enter 10 digit mobile number");
                e.Handled = true;
            }
        }

        private void txtPIN_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) || (int)e.KeyChar == 8)
            {
                e.Handled = false;
                ClearError();
            }

            else
            {
                errorProvider1.SetError(txtPIN, "Please enter 6 digit pin number");
                e.Handled = true;
            }
        }

        private void txtHomePhone_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) || (int)e.KeyChar == 45 || (int)e.KeyChar == 8)
            {
                e.Handled = false;
                ClearError();
            }

            else
            {
                errorProvider1.SetError(txtHomePhone, "Please enter Home Phone Number");
                e.Handled = true;
            }
        }

        private void txtName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsLetter(e.KeyChar) || (int)e.KeyChar == 8)
            {
                e.Handled = false;
                ClearError();
            }            
            else
            {
                errorProvider1.SetError(txtName, "Number and special character not allowed");
                e.Handled = true;

            }
        }           

        

        private void txtLname_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsLetter(e.KeyChar) || (int)e.KeyChar == 8)
            {
                e.Handled = false;
                ClearError();
            }
            else
            {
                errorProvider1.SetError(txtLname, "Number and special character not allowed");
                e.Handled = true;

            }
        }

        private void txtMname_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsLetter(e.KeyChar) || (int)e.KeyChar == 8)
            {
                e.Handled = false;
                ClearError();
            }
            else
            {
                errorProvider1.SetError(txtMname, "Number and special character not allowed");
                e.Handled = true;

            }
        }

           
        
    }
}
                
            
        

    

        
    




                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  